﻿<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: list.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('enterprise_list_page_title'));

$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
	->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.datepicker.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css');

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.droppable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js')
	->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.datepicker.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><?php echo $this->translator('enterprise_list_breadcump'); ?></span>
</div>
<div class="grid_12 t_a_bottom">
	<div class="grid_12"><?php echo $this->translator('enterprise_list_guide'); ?></div>
</div>

<form  action="" method="POST">
	<div>
		<div class="grid_12 t_a_bottom">
			<label><?php echo $this->translator("enterprise_filter");?></label>
		</div>
		<div class="grid_12 t_a_bottom">
			<div class="grid_5 alpha">
				<label><?php echo $this->translator("enterprise_filter_name");?></label>
				<input type="text" name="company_name" value="<?php echo $this->company_name?>">
			</div>
			<div class="grid_4 omega">
				<label style="width:auto;"><?php echo $this->translator("enterprise_tax_code");?></label>
				<input type="text" name="registration_number" value="<?php echo $this->registration_number;?>">
			</div>
			<hr/>
		</div>		
		<div class="grid_12 t_a_bottom">
			<div class="grid_5 alpha">
				<label><?php echo $this->translator("enterprise_filter_registration_date_from");?></label>
				<input type="text" class="txtDatePicker" name="registration_date_from" value="<?php echo $this->registration_date_from?>">
			</div>
			<div class="grid_4 omega">
				<label style="width:auto;"><?php echo $this->translator("enterprise_registration_data_to");?></label>	
				<input type="text" class="txtDatePicker" name="registration_date_to" value="<?php echo $this->registration_date_to?>">
			</div>
			<hr/>
		</div>
		<div class="grid_12 t_a_bottom">
			<div class="grid_5 alpha">
				<label><?php echo $this->translator("enterprise_professions");?></label>	
				<select name="sltProfession">
					<option value="">--<?php echo ($this->lang=='vi_VN')?" tất cả ":" all ";?> --</option>
					<?php foreach($this->professions as $item):?>
						<option value="<?php echo $item->professions_id;?>" <?php if($this->sltProfession==$item->professions_id) echo ' selected="selected" ';?>><?php echo ($this->lang=='vi_VN')?$item->professions_name:$item->professions_name_en;?></option>
					<?php endforeach;?>
				</select>
			</div>
			<hr/>
		</div>
		<div class="grid_12 t_a_bottom">
			<label><?php echo $this->translator("enterprise_application");?></label>
			<select name="sltApplication">
				<option value=""  <?php if(!isset($this->sltApplication)) echo "selected='selected'";?> >--<?php echo ($this->lang=='vi_VN')?" tất cả ":" all ";?> --</option>
				<option value="0" <?php if(isset($this->sltApplication) &&  ($this->sltApplication == 0)) echo "selected='selected'";?>><?php echo $this->translator("application_zero");?></option>
				<option value="1" <?php if(isset($this->sltApplication) &&  ($this->sltApplication == 1)) echo "selected='selected'";?>><?php echo $this->translator("application_one");?></option>
			</select>
		</div>
	</div>
	<div class="grid_12 t_a_bottom">    
		<button type="submit"><span><?php echo $this->translator("enterprise_filter");?></span></button>
	</div>
</form>
<script type="text/javascript">
	$(document).ready(function(){
		$(".txtDatePicker").datepicker({
			"dateFormat" : 'yy-mm-dd'
		});
	});
</script>
<div class="grid_12 t_a_bottom">    
	<div class="grid_9 alpha">&nbsp;</div>
    <div class="grid_3 omega">
        <div class="t_a_right">
            <a href="<?php echo $this->url(array(), 'enterprise_enterprise_add'); ?>" class="t_a_ui_button_link"><span><?php echo $this->translator('enterprise_add_breadcrump'); ?></span></a>
        </div>
    </div>
</div>

<!-- List of enterprise -->
<?php if ($this->numEnterprise == 0) : ?>
<div class="grid_12 t_a_bottom">
    <?php echo $this->translator('enterprise_list_not_found'); ?>
</div>
<?php else : ?>
<div class="grid_12 t_a_ui_data_list_header">
    <div class="grid_4 alpha" style="width:250px">
        <div><!--<input type="checkbox" id="checkAll" />--> <?php echo $this->translator('enterprise_company_name'); ?></div>
    </div>
    <div class="grid_2"><?php echo $this->translator('enterprise_status'); ?></div>
    <div class="grid_2"><?php echo $this->translator('enterprise_list_registration_number'); ?></div>
    <div class="grid_1"><?php echo $this->translator('enterprise_list_registration_date'); ?></div>
    <div class="grid_1" style="width:90px"><?php echo $this->translator('enterprise_list_registration_city'); ?></div>
    <div class="grid_1" style="width:80px"><?php echo $this->translator('enterprise_account_valid_until'); ?></div>
    <div class="grid_1 omega"><?php echo $this->translator('enterprise_id'); ?></div>
</div>

<div class="grid_12 t_a_bottom" id="articles">
    <style>
        .css_expired{
            //color: #FF0000;
            background: #990000;
        }
        .css_expired:hover{
            background: #990000;
        }
    </style>
    <?php foreach ($this->enterprise as $row) : ?>
        <?php
            /**
            * Check expiry date
            */
            $valid_date = '&nbsp';
            $class = null;
            if(isset($this->arValidDate[$row->id])){
                $valid_date = $this->arValidDate[$row->id]->account_valid_until_date;
                $current_date = strtotime(date('Y-m-d'));
                if(strtotime($valid_date) < $current_date){
                    $class = "css_expired";
                }
            }else{
                $class = "css_expired";
            }
        ?>
    <div id="enterpriseRow_<?php echo $row->id; ?>" class="clearfix t_a_ui_data_list_content <?php echo $class;?>">
        <div class="grid_4 alpha"  style="width:250px">
            <div>
                <!--<input type="checkbox" class="selectEnterprise" value="<?php echo $row->id; ?>" />-->
                <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_edit'); ?>"><?php echo $row->company_name_vn;?></a>
            </div>

            <div class="t_a_top t_a_ui_helper_action">
                <?php if ($this->allow('edit')) : ?>
                <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_edit'); ?>"><?php echo $this->translator('enterprise_list_action_edit'); ?></a>
                <?php endif; ?>

                <?php if ($this->allow('payment-info')) : ?>
                 | <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_payment_info'); ?>"><?php echo $this->translator('enterprise_list_action_edit_payment_info'); ?></a>
                <?php endif; ?>

                <?php if ($this->allow('enterprise-info')) : ?>
                 | <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_info'); ?>/vi_VN"><?php echo $this->translator('enterprise_list_action_edit_enterprise_info_vn'); ?></a>
                 | <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_info'); ?>/en_US"><?php echo $this->translator('enterprise_list_action_edit_enterprise_info_en'); ?></a>
                <?php endif; ?>

                <?php if ($this->allow('user-account')) : ?>
                 | <a href="<?php echo $this->url(array('enterprise_id' => $row->id), 'enterprise_enterprise_user_account'); ?>"><?php echo $this->translator('enterprise_list_action_edit_user_account'); ?></a>
                <?php endif; ?>

                <?php if ($this->allow('delete')) : ?>
                 | <a class="deleteAction" rel="<?php echo $row->id; ?>" href="javascript: void(0);"><?php echo $this->translator('enterprise_list_action_delete'); ?></a>
                <?php endif; ?>
            </div>
        </div>
        <div class="grid_2">
            <?php
                $frontend = ($row->frontend_active==1)?$this->translator('enterprise_frontend_status_active'):$this->translator('enterprise_frontend_status_inactive');
                $backend = ($row->backend_active==1)?$this->translator('enterprise_backend_status_active'):$this->translator('enterprise_backend_status_inactive');
            ?>
            <?php if($row->application == 1):?>
            <span style="color:#FF0000"><?php echo $this->translator('enterprise_list_wait_approve');?></span><br/>
            <?php endif;?>
            <?php echo $this->translator('enterprise_list_frontend_active')?>: <?php echo $frontend; ?><br/>
            <?php echo $this->translator('enterprise_list_backend_active')?>: <?php echo $backend; ?>
        </div>
        <div class="grid_2">
            <?php echo $row->registration_number; ?>&nbsp;
        </div>
        <div class="grid_1">
            <?php echo $row->registration_date; ?>&nbsp;
        </div>
        <div class="grid_1"  style="width:90px">
            <?php echo $row->registration_city; ?>&nbsp;
        </div>
        <div class="grid_1"  style="width:80px">
            <span><?php echo $valid_date;?></span>
        </div>
        <div class="grid_1 omega"><?php echo $row->id;?></div>
    </div>
    <?php endforeach; ?>
</div>

<div class="grid_12 t_a_bottom t_a_paginator">
    <?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions);?>
</div>
<?php endif; ?>

<div id="messageDialog"></div>
<div id="confirmDialog"></div>

<script type="text/javascript">
$(document).ready(function() {
    <?php if ($this->allow('delete')) : ?>
    $('a.deleteAction').click(function() {
        var self = this;
        $('#confirmDialog').html('<?php echo addslashes($this->translator('enterprise_list_action_delete_confirm')); ?>')
            .dialog({
                title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
                dialogClass: 't_a_ui_dialog',
                modal: true,
                closeOnEscape: false,
                resizable: false,
                open: function(event, ui) {
                    $('.ui-dialog-titlebar-close').hide();
                    $(this).parent().find('.ui-dialog-buttonpane button').wrapInner('<span/>');
                },
                buttons: {
                    '<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
                        $(this).dialog('destroy');
                    },
                    '<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
                        $(this).dialog('destroy');
                        $(self).html('').addClass('t_a_ui_helper_loading');
                        var id = $(self).attr('rel');
                        $.ajaxq('enterprise', {
                            type: 'POST',
                            url: "<?php echo $this->url(array(), 'enterprise_enterprise_delete'); ?>",
                            data: { id: id },
                            success: function(response) {
                                if ('RESULT_OK' == response) {
                                    $('#enterpriseRow_' + id).fadeOut('slow');
                                }
                            }
                        });
                    }
                }
            });
    });
    <?php endif; ?>
});
</script>